package com.jie.servlet;

import com.alibaba.fastjson.JSON;
import com.jie.service.impl.AgencyServiceImpl;
import com.jie.util.ExportExcelUtil;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * Created by 12904 on 2018/8/13.
 */
@WebServlet(name = "exportExcelServlet")
public class exportExcelServlet extends HttpServlet
{
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
    {

        request.setCharacterEncoding("utf-8");
        response.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=utf-8");
        String data = JSON.toJSONString(new AgencyServiceImpl().find(0,new AgencyServiceImpl().find()));
        String url = request.getParameter("url");
        ExportExcelUtil.exportExcel(data,url);
        response.sendRedirect("indexServlet");
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
    {
        doPost(request,response);
    }
}
